﻿using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Media;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    [ValueConversion(typeof(object[]), typeof(string))]
    internal class TimeLineTotalDurationMultiBindingConvert : IMultiValueConverter
    {
        private readonly static string DefaultZero = Tools.GetTimeSpanToString_HoursMinutesSecondsDigit(TimeSpan.Zero);
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            double? MaxTime = values.OfType<double>().FirstOrDefault();
            int? ZoomLevel = values.OfType<int>().FirstOrDefault();
            DoubleCollection? TimeRangeEdges = values.OfType<DoubleCollection>().FirstOrDefault();

            if (!MaxTime.HasValue)
                return DefaultZero;
            TimeSpan maxTime = TimeSpan.FromMilliseconds(MaxTime.Value);
            if (!ZoomLevel.HasValue || ZoomLevel == 0 || TimeRangeEdges == null || TimeRangeEdges.Count != 2)
                return Tools.GetTimeSpanToString_HoursMinutesSecondsDigit(maxTime);
            return $"[{Tools.GetTimeSpanToString_HoursMinutesSecondsDigit(TimeSpan.FromMilliseconds(TimeRangeEdges.Max() - TimeRangeEdges.Min()))}] / [{Tools.GetTimeSpanToString_HoursMinutesSecondsDigit(maxTime)}]";
        }


        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
